home *** CD-ROM | disk | FTP | other *** search
- //========================================================================
- // PCScrLib.c - Common screen saver routines
- //
- // Douglas Boling
- //
- // Copyright (c) 1992 Doulgas Boling
- //========================================================================
-
- #include <windows.h>
- #include "pcscrlib.h"
-
- //------------------------------------------------------------------------
- //Function prototypes used by all screen savers
- //------------------------------------------------------------------------
- BOOL RegisterDialogClasses (HANDLE hInst);
- LONG FAR PASCAL ScreenSaverProc(HWND, WORD, WORD, LONG);
- extern BOOL FAR PASCAL ScreenSaverConfigureDialog(HWND hDlg, WORD msg,
- WORD wParam, LONG lParam);
- LONG FAR PASCAL DefScreenSaverProc(HWND, WORD, WORD, LONG);
-
- //------------------------------------------------------------------------
- //Global Data for all screen savers
- //------------------------------------------------------------------------
- extern HANDLE hMainInstance;
- extern HWND hMainWindow;
- extern char szAppName[];
-
- //========================================================================
- //WinMain - This routine provides the WinMain routine for a Windows
- // screen saver.
- //========================================================================
- int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdParam, int nCmdShow) {
-
- HWND hMainWindow;
- MSG msg;
- WNDCLASS wndclass;
- char cSwitch;
- FARPROC lpfnDlgProc;
-
- hMainInstance = hInstance;
-
- if (hPrevInstance)
- return 1;
-
- //----------------------------------------------------------------
- //If the command line has a -s, /s, or s, start screen saver
- //----------------------------------------------------------------
-
- cSwitch = lpszCmdParam[0];
- if (cSwitch == '/' || cSwitch == '-')
- cSwitch = lpszCmdParam[1];
-
- if (cSwitch == 's' || cSwitch == 'S') {
-
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = ScreenSaverProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon (hInstance, MAKEINTATOM (ID_APP));
- wndclass.hCursor = NULL;
- wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = szAppName;
-
- if (!RegisterClass (&wndclass))
- return 1;
-
- hMainWindow = CreateWindow (szAppName, szAppName,
- WS_POPUP | WS_VISIBLE, 0, 0,
- GetSystemMetrics (SM_CXSCREEN),
- GetSystemMetrics (SM_CYSCREEN),
- NULL, NULL, hInstance, NULL);
- if (!hMainWindow)
- return 1;
-
- //-------------------------------------------------------------------
- //Use the following code for a standard dispatch loop.
- //-------------------------------------------------------------------
- // while (GetMessage(&msg,NULL,0,0)) {
- // TranslateMessage(&msg);
- // DispatchMessage(&msg);
- // }
- // return msg.wParam;
-
- //-------------------------------------------------------------------
- //Bugs uses a modified dispatch loop to process bugs whenever
- //there isn't a message in the queue.
- //-------------------------------------------------------------------
- while (TRUE) {
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- if (msg.message == WM_QUIT) break;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- } else {
- BugSmarts(hMainWindow);
- }
- }
- return msg.wParam;
-
- } else {
- //----------------------------------------------------------------
- // If no cmd line switch, display config dialog box.
- //----------------------------------------------------------------
- lpfnDlgProc = MakeProcInstance(ScreenSaverConfigureDialog,
- hInstance);
- if (RegisterDialogClasses (hInstance)) {
- DialogBox (hInstance, DLG_SCRNSAVECONFIGURE, NULL, lpfnDlgProc);
- FreeProcInstance (lpfnDlgProc);
- }
- return 0;
- }
- }
-
- //========================================================================
- //Default Windows proc for a screen saver
- //
- //The task of the default screen saver proc is simple, quit if the user
- // provides any input to the machine.
- //========================================================================
- LONG FAR PASCAL DefScreenSaverProc (HWND hwnd, WORD message,
- WORD wParam, LONG lParam) {
- static POINT pLastMousePos = {-1, -1};
- POINT pCurrMousePos;
-
- switch (message) {
-
- case WM_ACTIVATE:
- if (wParam == 0)
- PostMessage (hwnd, WM_CLOSE, 0, 0);
- else
- GetCursorPos (&pLastMousePos);
- break;
-
- case WM_MOUSEMOVE:
- SetCursor (0);
- GetCursorPos (&pCurrMousePos);
-
- if (pLastMousePos.x == -1 || pLastMousePos.y == -1) {
- GetCursorPos (&pLastMousePos);
- break;
- }
- if (pCurrMousePos.x != pLastMousePos.x)
- PostMessage (hwnd, WM_CLOSE, 0, 0);
-
- if (pCurrMousePos.y != pLastMousePos.y)
- PostMessage (hwnd, WM_CLOSE, 0, 0);
-
- break;
-
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDOWN:
- case WM_RBUTTONDOWN:
- case WM_SYSKEYDOWN:
- case WM_KEYDOWN:
- PostMessage (hwnd, WM_CLOSE, 0, 0);
- break;
-
- case WM_DESTROY:
- PostQuitMessage (0);
- return 0;
- }
- return DefWindowProc (hwnd, message, wParam, lParam);
- }
-
-